<?php  

require_once('../../config.php');
require_once('quail/quail.php');
require_once('filter.php');
print_header("Accessibility Overview");
$quail = new quail($_POST['text'], $CFG->filter_accessibility_guideline, 'string', 'array');
$quail->setOption('cms_mode', TRUE);
$quail->runCheck();
$report = $quail->getReport(array('display_level' => $CFG->filter_accessibility_display_level));
$report = accessibility_filter_cleanup_report($report);
foreach($report as $severity => $tests) {
	if($tests['total'] > 0) {
		print '<div class="test-group">';
		print '<h3>'. getSeverityText($severity) .'</h3>';
		unset($tests['total']);
		foreach($tests as $testname => $test) {
			print '<div class="test-fail">';
			print '<h5>'. $test['title'] .'</h5>';
			print '<div class="test-description">'. $test['body'] .'</div>';
			if(is_array($test['problems'])) {
				print '<ul>';
				foreach($test['problems'] as $problem) {
					if($problem['element']) {
						print '<li>';
						if($problem['line']) {
							print '<strong>'. get_string('line', 'filter_accessibility');
							print $problem['line'] .'</strong> ';
						}
						print $problem['element'];
						print '</li>';
					}
				}
				print '</ul>';
			}
			print '</div>';
		}
		
		print '</div>';
	}
}
print_footer();


function getSeverityText($severity) {
	$text = array(
		QUAIL_TEST_SEVERE => get_string('severe', 'filter_accessibility'),
		QUAIL_TEST_MODERATE => get_string('moderate', 'filter_accessibility'),
		QUAIL_TEST_SUGGESTION => get_string('suggestion', 'filter_accessibility'),
	);
	return $text[$severity];
}